<?php /** @noinspection PhpPropertyCanBeReadonlyInspection */
/** @noinspection PhpPropertyCanBeReadonlyInspection */
/** @noinspection PhpPropertyCanBeReadonlyInspection */

declare(strict_types=1);

namespace Dreamcat\ApiDoc;

/**
 * 接口文档处理器
 * @author vijay
 */
class ApiDoc
{
    /**
     * @param ApiDefineGeneratorInterface $apiDefineGenerator api定义解析
     * @param RouteDefineScanInterface $routeDefineScan 路由扫描器
     * @param DocSaverInterface $docSaver 文档保存器
     */
    public function __construct(
        private ApiDefineGeneratorInterface $apiDefineGenerator,
        private RouteDefineScanInterface $routeDefineScan,
        private DocSaverInterface $docSaver
    ) {
    }

    /**
     * 保存文档
     * @param string $projectPath 项目地址
     * @return void
     */
    public function save(string $projectPath): void
    {
        $list = $this->routeDefineScan->scanRouteList($projectPath);
        $this->docSaver->start();
        foreach ($list as $definition) {
            $this->docSaver->saveApiDefinition($this->apiDefineGenerator->parseApi($definition));
        }
        $this->docSaver->end();
    }
}

# end of file
